package simple_factory_pattern.v2;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入数字A: ");
        String strNumberA = sc.next();
        System.out.print("请选择运算符号（+、-、*、/）: ");
        String strOperate = sc.next();
        System.out.print("请输入数字B: ");
        String strNumberB = sc.next();
        String strResult = "";
        switch (strOperate) {
            case "+":
                strResult = Double.parseDouble(strNumberA) + Double.parseDouble(strNumberB) + "";
                break;
            case "-":
                strResult = Double.parseDouble(strNumberA) - Double.parseDouble(strNumberB) + "";
                break;
            case "*":
                strResult = Double.parseDouble(strNumberA) * Double.parseDouble(strNumberB) + "";
                break;
            case "/":
                if (strNumberB.equals("0")) {
                    strResult = "除数不能为0！";
                } else {
                    strResult = Double.parseDouble(strNumberA) / Double.parseDouble(strNumberB) + "";
                }
                break;
            default:
                System.out.println("您的输入不合法！");
                break;
        }
        System.out.println("结果是: " + strResult);
    }
}
